package com.example.springboot.service.impl;

import com.example.springboot.dao.ResourceCategoryMapper;
import com.example.springboot.domain.ResourceCategory;
import com.example.springboot.domain.ResponseResult;
import com.example.springboot.service.ResourceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class ResourceCategoryServiceImpl implements ResourceCategoryService {

    @Resource
    private ResourceCategoryMapper resourceCategoryMapper;


    @Override
    public List<ResourceCategory> findAllResourceCategory() {

        List<ResourceCategory> allResourceCategory = resourceCategoryMapper.findAllResourceCategory();

        return allResourceCategory;
    }

    @Override
    public void addResource(ResourceCategory resourceCategory) {
        Date date = new Date();
        resourceCategory.setCreatedTime(date);
        resourceCategory.setUpdatedTime(date);
        resourceCategory.setCreatedBy("system");
        resourceCategory.setUpdatedBy("system");
        resourceCategoryMapper.addResource(resourceCategory);
    }

    @Override
    public void updateResource(ResourceCategory resourceCategory) {
        Date date = new Date();
        resourceCategory.setUpdatedTime(date);
        resourceCategory.setUpdatedTime(date);
        resourceCategoryMapper.updateResource(resourceCategory);
    }

    @Override
    public void deleteResourceCategory(int id) {
        //去除中间表
        resourceCategoryMapper.deleteResource(id);

        resourceCategoryMapper.deleteResourceCategory(id);
    }

}
